#ifndef MYUTILS_H
#define MYUTILS_H

#include <e32cmn.h>
#include <f32file.h>
#include "mk4.h"
#include "mk4str.h"
#include <coemain.h>


class DBUtil : public CCoeStatic
	{
public:
	static DBUtil* Static();
	DBUtil();
	~DBUtil();
	void ConstructL();
	
	//db
	int FieldIntValue(c4_View* view, char* fieldname, int pos);
	TPtrC8 FieldStr8Value(c4_View* view, char* fieldname, int pos);
	TPtrC FieldUnicodeValue(c4_View* view, char* fieldname, int pos, bool carriageconvert = false);
	TPtrC8 FieldUtf8Value(c4_View* view, char* fieldname, int pos);
	int FindByInt(c4_View* view, char* fieldname, int keyvalue);
	int FindByStr(c4_View* view, char* fieldname, char* keyvalue);
	//str
	void ConvertDesToStr(const TPtrC& source, char* dest);
	bool FindBookPrefix(const TPtrC& path);
	TPtrC GetRealPath(const TPtrC& path);
	TPtrC GetPageFunc(const TPtrC& path);
	TPtrC GetPageDesPara(const TPtrC& path, int paraindex = 0);	
	int GetPageIntPara(const TPtrC& path, int paraindex = 0);
	TPtrC GetUriFileName(const TPtrC& path);
private:
	c4_String iStrTemp;
	};

//from hcUtils
class StrUtils
{
public:
	static TUint32 StrToInt(const TDesC& aSource, TRadix aRadix=EDecimal);
	static TBool StrToBool(const TDesC& aSource);

	static void Trim(TPtrC& aDest);
	static void TrimRedundant(TDes& aDest);
	static TBool IsEmptyText(const TDesC& aSource);

	static HBufC* StringReplaceL(const TDesC& aSource, const TDesC& aTarget, const TDesC& aReplacement);
	static void StringReplace(const TDesC& aSource, const TDesC& aTarget, const TDesC& aReplacement, TDes& aDest);
	static void StringReplace(TDes& aTarget, TChar aSrcChar, TChar aDestChar);
	static TBool StringSplit(const TDesC& aSource, TInt& aOffset, TChar aSeperator, TPtrC& aRet);

	static TInt EnumTag(const TDesC& aSource, TInt aOffset, TDes& aTagName, TInt& aLength, TInt& aTagType);
	static TInt FindTag(const TDesC& aSource, TInt aOffset, const TDesC& aTagName, TBool aStartOrEnd, TInt& aLength);

	static TInt EnumAttribute(const TDesC& aSource, TInt aOffset, TDes& aAttrName, TInt& aAttrLength, TInt& aValueStart, TInt& aValueLength);
	static TInt GetAttributeValue(const TDesC& aSource, const TDesC& aAttrName, TPtrC& aDest);
	static TInt GetAttributeValue(const TDesC& aSource, const TDesC& aAttrName, TDes& aDest);
};

class MyImgFile
{
public:
	MyImgFile();
	~MyImgFile();
public:
	const TPtrC8 ImgBlock(int pos, int size);
	void ReleaseBlock();
	void Init(const TDesC& FileName);
	void SaveToFile(const TDesC8& data);
	int Length(); //current file size
private:
	bool iAllocated;
    RFile _rfile;
    RFs _fs;	
    HBufC8* iFileData8;
};

#endif
